/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.erp.client.widget;

import com.erp.client.DAO.FileInfo;
import com.erp.client.DAO.ServerUserBase;
import com.erp.client.DAO.ServerUserBaseAsync;
import com.erp.client.DAO.ServerUserBaseGetService;
import com.erp.client.DAO.UserBaseInf;
import com.erp.client.MessAge.myMessage;
import com.erp.client.MessAge.myMesswindow;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.StatusButtonBar;
import com.extjs.gxt.ui.client.widget.form.FileUploadField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class myFileDown extends Dialog{

    public String systemUserLabelName = "";
    public Integer loginstate = 0;
    public int StaticEmpID = 0;
    public int StaticDepId = 0;
    public String StaticUserName = "";
    public String StaticDepName = "";
    private myMessage mess = new myMessage();
    private String Stringreturn = "";
    private ServerUserBaseAsync service;
    private ListStore<BeanModel> store;
    private ListLoader loader;
    private Grid<BeanModel> grid;
    final private myMesswindow messdisp = new myMesswindow();
    protected FormPanel form;
    protected StatusButtonBar buttonBar;
    protected ServerUserBaseAsync customerService;

    public myFileDown() {
        AsyncCallback callback = new AsyncCallback() {

            @Override
            public void onSuccess(Object result) {
                Info.display("Event", "The '登录信息取回成功' ");
                List<UserBaseInf> lls = (List<UserBaseInf>) result;

                StaticEmpID = lls.get(0).getUserId();
                StaticDepId = lls.get(0).getDepId();
                StaticUserName = lls.get(0).getUserName();
                StaticDepName = lls.get(0).getDepName();
                systemUserLabelName = StaticUserName + "      [" + StaticDepName + "]";
                buildui();
            }

            @Override
            public void onFailure(Throwable caught) {
                Info.display("server", "server连接失败");
            }
        };
        ServerUserBaseGetService.getService().UserRightsGet(callback);
        System.out.print(StaticEmpID);

    }

    private void buildui() {
        final Window w = new Window();
        w.setPlain(true);
        w.setSize(340, 260);
        w.setHeading("文档查询");
        w.setLayout(new FitLayout());

        final FormPanel panel = new FormPanel();
        
        panel.setHeading("请选择文件");
        panel.setBorders(false);
        panel.setBodyBorder(false);
        panel.setLabelWidth(60);
        panel.setPadding(5);
        panel.setHeaderVisible(false);
        panel.setButtonAlign(HorizontalAlignment.CENTER);

        service = (ServerUserBaseAsync) GWT.create(ServerUserBase.class);
        ServiceDefTarget endpoint = (ServiceDefTarget) service;
        String moduleRelativeURL = GWT.getModuleBaseURL() + "dao/serveruserbase";
        endpoint.setServiceEntryPoint(moduleRelativeURL);

        //System.out.print(StaticEmpID);
        RpcProxy proxy = new RpcProxy() {

            @Override
            public void load(Object loadConfig, AsyncCallback callback) {
                service.getFileByID(StaticEmpID,callback);
                
            }
        };
        System.out.print(StaticEmpID);
        loader = new BaseListLoader(proxy, new BeanModelReader());
        store = new ListStore<BeanModel>(loader);
        loader.load();
        
        ColumnConfig fileid = new ColumnConfig("fileID", "文件序号", 60);
        ColumnConfig filename = new ColumnConfig("fileName", "文件全名", 100);
        ColumnConfig Myfile = new ColumnConfig("myfile", "文件名", 100);
        ColumnConfig username = new ColumnConfig("userName", "文档所有者", 60);
        ColumnConfig depname = new ColumnConfig("depName", "部门名称", 60);
        ColumnConfig filetype = new ColumnConfig("fileType", "文件类型", 60);
        ColumnConfig recdate = new ColumnConfig("recDate", "上传日期", 100);
        ColumnConfig delflag = new ColumnConfig("delFlag", "删除标志", 60);
        ColumnConfig empid = new ColumnConfig("empId", "记录者ID", 60);
        
        

        fileid.setHidden(true);
        empid.setHidden(true);
        filename.setHidden(true);
        delflag.setHidden(true);
        Myfile.setMenuDisabled(true);
        filetype.setMenuDisabled(true);
        username.setMenuDisabled(true);
        depname.setMenuDisabled(true);
        recdate.setMenuDisabled(true);
        List<ColumnConfig> config = new ArrayList<ColumnConfig>();
        config.add(fileid);
        config.add(empid);
        config.add(filename);
        config.add(delflag);
        config.add(Myfile);
        config.add(filetype);
        config.add(username);
        config.add(depname);
        config.add(recdate);
        final ColumnModel cm = new ColumnModel(config);
        grid = new Grid<BeanModel>(store, cm);
        grid.setWidth(400);
        grid.setBorders(true);
        grid.setAutoExpandColumn("fileID");
        panel.add(grid);

        //panel.setAction("com.erp.system/serverupload");
        //panel.setAction("com.erp.system/myfiledown?"+"id1=12"+"&id2=cd");
        Button btn = new Button("下载");
        btn.addSelectionListener(new SelectionListener<ButtonEvent>() {

            @Override
            public void componentSelected(ButtonEvent ce) {

                if (!panel.isValid()) {
                    return;
                }
                panel.submit();
                Info.display("系统提示", "文件传输成功！");
            //w.close();
            }
        });
        panel.addButton(btn);
        w.add(panel);
        w.show();
        
    }

}